﻿<Page x:Class="RunCmd.Views.HomeView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:ViewModels="clr-namespace:RunCmd.ViewModels"
        xmlns:hlpr="clr-namespace:RunCmd.Common.Helpers"
      xmlns:acb="clr-namespace:RunCmd.Common.AttachedCommandBehavior"
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
	Title="HomeView">
    <Page.DataContext>
        <ViewModels:HomeViewModel/>
    </Page.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1"></RowDefinition>
            <RowDefinition Height="3*" SharedSizeGroup="A"></RowDefinition>
            <RowDefinition Height="5"></RowDefinition>
           <RowDefinition Height="7*" SharedSizeGroup="A"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"></ColumnDefinition>
            <ColumnDefinition Width="5"></ColumnDefinition>
            <ColumnDefinition Width="8*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Line Grid.Row="0"></Line>
        <Grid Grid.Column="0" Grid.Row="1" Grid.RowSpan="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="24"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <DockPanel Grid.Row="0" LastChildFill="True" VerticalAlignment="Center">
                <TextBlock Text="Filter: " DockPanel.Dock="Left" VerticalAlignment="Center"></TextBlock>
                <TextBox DockPanel.Dock="Right" Text="{Binding BatFilesFilterText, UpdateSourceTrigger=PropertyChanged}" ></TextBox>
            </DockPanel>
                   <ScrollViewer Grid.Row="1" Height="Auto">
            <ListView  Name="lstBatFiles" BorderBrush="Gray" BorderThickness="1" ItemsSource="{Binding BatFilesView}" SelectedItem="{Binding SelectedBatFile}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="0" hlpr:MouseDoubleClick.Command="{Binding RunCmd}">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="VerticalContentAlignment" Value="Stretch" />
                        <Setter Property="Background" Value="Gray" />
                        <Setter Property="Margin" Value="0" />
                        <Setter Property="Padding" Value="0"/>
                        <!--<Setter Property="acb:CommandBehavior.Event" Value="MouseDoubleClick" />
                        <Setter Property="acb:CommandBehavior.Command" Value="{Binding ElementName=lstBatFiles,Path=DataContext.RunCmd}" />
                        <Setter Property="acb:CommandBehavior.CommandParameter" Value="{Binding}" />-->
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding TextFileNameDisplay}" Margin="5" Padding="0" Width="{Binding ElementName=Container,Path=ActualWidth}"  TextWrapping="WrapWithOverflow" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBlock>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </ScrollViewer>
        </Grid>
 
        <GridSplitter Grid.Column="1" Grid.RowSpan="4" Width="5" HorizontalAlignment="Stretch" ResizeDirection="Columns">
            <GridSplitter.Template>
                <ControlTemplate TargetType="{x:Type GridSplitter}">
                    <Grid>
                        <Button Content="⁞" />
                        <Rectangle Fill="#00FFFFFF" />
                    </Grid>
                </ControlTemplate>
            </GridSplitter.Template>
        </GridSplitter>
        <Grid Grid.Column="2" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="32"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="24"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <TextBox Grid.Column="0" Grid.Row="0" Text="{Binding SelectedBatFile.TextFileNameDisplay, Mode=TwoWay}" HorizontalAlignment="Stretch"></TextBox>
                <TextBox AcceptsReturn="{Binding IsCustomExe, Converter={StaticResource inverseBooleanConverter}}" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding SelectedBatFile.CmdText, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />
            </Grid>
            <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="0" Grid.Row="1" Height="32" VerticalAlignment="Stretch">
                <Grid Grid.Column="0" Grid.Row="1"  Name="grdButtons">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="28"></ColumnDefinition>
                        <ColumnDefinition Width="28"></ColumnDefinition>
                        <ColumnDefinition Width="28"></ColumnDefinition>
                        <ColumnDefinition Width="28"></ColumnDefinition>
                        <ColumnDefinition Width="50"></ColumnDefinition>
                        <ColumnDefinition Width="50"></ColumnDefinition>
                        <ColumnDefinition Width="50"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Name="txtExePath" Text="{Binding ExeFileName}" Grid.Column="0" TextWrapping="WrapWithOverflow"></TextBlock>
                    <Button Name="btnExePath" Grid.Column="1" Command="{Binding ExeFilePickCmd}" Style="{StaticResource pickerButtonCentered}" />
                    <CheckBox Name="chkIsDefault" Grid.Column="2" IsChecked="{Binding IsCustomExe}" Style="{StaticResource chkCentered}"/>
                    <Button Name="BtnSave" Content="Save" Grid.Column="3" Style="{StaticResource buttonCentered}" Command="{Binding SaveCmd}"  />
                    <Button Name="BtnNew" Content="New" Grid.Column="4" Style="{StaticResource buttonCentered}" Command="{Binding NewBatFileCmd}"  />
                    <Button Name="BtnExecute" Content="Run" Grid.Column="5" Style="{StaticResource buttonCentered}" Command="{Binding RunCmd}" />
                    <Button Name="BtnStop" Content="Stop" Grid.Column="6" Style="{StaticResource buttonCentered}" Command="{Binding StopCmd}" />
                </Grid>
            </Border>

        </Grid>

        <GridSplitter Grid.Column="2" Grid.Row="2" Height="5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ResizeDirection="Rows" VerticalContentAlignment="Center" HorizontalContentAlignment="Center">
            <GridSplitter.Template>
                <ControlTemplate TargetType="{x:Type GridSplitter}">
                    <Grid>
                        <Button Content="····" />
                        <Rectangle Fill="#00FFFFFF" />
                    </Grid>
                </ControlTemplate>
            </GridSplitter.Template>
        </GridSplitter>
        <Grid Grid.Column="2" Grid.Row="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="24"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <ScrollViewer Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <TextBox  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding TxtOutput}" hlpr:TextBoxBehaviour.ScrollOnTextChanged="True" BorderBrush="Gray" BorderThickness="1"></TextBox>
            </ScrollViewer>
            <Label Content="Input" Grid.Column="0" Grid.Row="1"></Label>
            <TextBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding TxtInput}" IsEnabled="{Binding IsCmdRunning}">
                <TextBox.InputBindings>
                    <KeyBinding Key="Return" Command="{Binding SendInputCmd}" />
                </TextBox.InputBindings>
            </TextBox>
        </Grid>
    </Grid>
</Page>
